

var AuthUserRigthModel = $.extend(TradeModel, {
    selRow: null, 
    editor:{
	    title: "属性",
		winid:'AuthUserRigth_EditForm',
		formid:'AuthUserRigth_EditForm_fm',
		width:720,
		height:300
	},  
    postAction: 'add',
    url: '/sysmgr/authuserrigth', 
    title: "标题",
    idField: "id",
    titleField: "id",
    toolbar: 'AuthUserRigth_Toolbar',
    datagrid: 'AuthUserRigth_Grid' 
}); 
 
AuthUserRigthModel.reload =function() {
	ReloadAuthUserRigthList();
	$('#AuthUserRigth_EditForm').dialog('close'); 
} 


function fun_FindRowById(id) {
    var cRows = $('#AuthUserRigth_Grid').datagrid('getRows');
    if (id == undefined || id == '' || id == null) return null;
    for (i = 0; i < cRows.length; i++) {
        if (cRows[i][AuthUserRigthModel.idField] == id) {
            return cRows[i];
        }
    }
    return null;
}




function ShowAuthUserRigthEditForm(id) {  
    AuthUserRigthModel.selRow = fun_FindRowById(id);
    if (AuthUserRigthModel.selRow == null) {
    	AuthUserRigthModel.selRow={};
        AuthUserRigthModel.postAction = 'add';
    }
    else {
        AuthUserRigthModel.postAction = 'update';
    } 
      
    $('#AuthUserRigth_EditForm_fm').form('clear' );
    $('#AuthUserRigth_EditForm_fm').form('load', AuthUserRigthModel.selRow);
    $('#AuthUserRigth_EditForm').dialog({
        top: "50px",
        resizable: false,
        maximizable: false 
    })
    .dialog('open')
    .dialog('setTitle', (AuthUserRigthModel.postAction == 'Add') ? '新增' + AuthUserRigthModel.title : '修改' + AuthUserRigthModel.selRow[AuthUserRigthModel.titleField]);
}
function SaveAuthUserRigth() {
	AuthUserRigthModel.submit();
	
}
function DelAuthUserRigth( id,title) {
	AuthUserRigthModel.del(id,title);
} 

function fun_App_USERSearchbox(value, name) {
    if (value == "" || value == null) {
        $.messager.alert('提示', '请输入关键字!', 'info');
    }
    else {
        $('#App_USER_Grid').datagrid('reload');
    }

}
function fun_ReloadApp_USERList() {
    $('#App_USER_Grid').datagrid('reload');
} 


function AuthUserRigthSearchbox(value, name) {
    if (value == "" || value == null) {
        $.messager.alert('提示', '请输入关键字!', 'info');
    }
    else {
        $('#AuthUserRigth_Grid').datagrid('reload');
    }

}
 
function ReloadAuthUserRigthList() {
    $('#AuthUserRigth_Grid').datagrid('reload');
}
 


$(function () {   
	
	 $('#App_USER_Grid').datagrid({ 
	        fit: true,
	        singleSelect: true,
	        fitColumns: true,
	        pagination: true, //分页控件 
	        method: 'get',
	        idField: 'userId',
	        url: Onluy.basePath()+ '/sysmgr/user/list',
	        loader:AuthUserRigthModel.Loader,
	        toolbar: '#App_USER_Toolbar', 
	        columns: [
	             [
	             	{ field: 'userName', title: '员工列表', width: 300, formatter: function (value, row) { return value + '&nbsp;&nbsp;&nbsp;<span style="color:#cecece">(&nbsp;' + row['webName'] + '&nbsp;)</span>'; } }
	           ]
	        ],
	        
	        onLoadError: function (res) {
	        	AuthUserRigthModel.ShowException(res); 
	        },
	        onSelect: function (rowIndex, rowData) {
	        	ReloadAuthUserRigthList() ;
	        }, 
	        onBeforeLoad: function (param) { 
	        	param['departId']=$.cookie('Depart_ID');
	            if (!param['departId']) {
	                param['departId'] = '2';
	            } 
	            param['catchKey'] = Math.random();
	            param['name'] = $('#App_USER_ss').searchbox('getName');
	            param['value'] = $('#App_USER_ss').searchbox('getValue');
	        }
	    });
	    //设置分页控件  
	    var p = $('#App_USER_Grid').datagrid('getPager');
	    $(p).pagination({
	        pageSize: 20, //每页显示的记录条数，默认为10  
	        pageList: [20, 30, 50, 100], //可以设置每页记录条数的列表  
	        beforePageText: '', //页数文本框前显示的汉字  
	        afterPageText: '/ {pages}',
	        displayMsg: '共{total}',
	        onBeforeRefresh: function () {
	            $(this).pagination('loading');
	            $(this).pagination('loaded');
	        }
	    });
	
	
    $('#AuthUserRigth_Grid').datagrid({
        pageSize: 20,
        fit: true,
        singleSelect: false,
        checkbox: true,
        rownumbers: false,
        fitColumns: true,
        pagination: true,  
        method: 'post',
        idField: AuthUserRigthModel.idField,
        treeField: AuthUserRigthModel.titleField,
        url: Onluy.basePath()+AuthUserRigthModel.url+'/list',
        loader:AuthUserRigthModel.Loader,
        loadFilter: function(res){  
	        	var i=0;  
		        	for(i=0;i<res.rows.length;i++){  
		        		if(res.rows[i].ck>0){
		        			res.rows[i].checked=true  ; 
		        		}else{
		        			res.rows[i].checked=false  ;
		        		} 
		        	} 
	        	//alert(JSON.stringify(res.rows));
	            return res;    
	    },
        toolbar: '#AuthUserRigth_Toolbar', 
        columns: [
            [  
            	{field:'ck',checkbox:true },
            	{ field: 'memo', title: '说明', width:100, align: 'left' } ,
            	{ field: 'dataid', title: '数据标识', width:200, align: 'left',sortable:true }
            ]
        ],
        onLoadSuccess: function (data) {
            if(data.success){
       		
       	}
       	else{
       		 $.messager.alert('提示', data.msg );
       	} 
       }, 
        onLoadError: function (res) {
        	AuthUserRigthModel.ShowException(res); 
        }, 
        
        
        onCheck: function (rowIndex, rowData) { 
        	var url = Onluy.basePath()+AuthUserRigthModel.url+'/add'; 
          
        		Onluy.ajax.getData(url,rowData,Onluy.secretkey, function(result){
        			 var success = result.success;
        			 //Onluy.easyui.ShowMsg(success ? "提示" : "错误",result.msg);
        	         if (success) { 
        	        	 
        	         }
        		},function(error){
        			//AuthUserRigthModel.ShowException(error);
        		} ); 
        }, 
        onUncheck: function (rowIndex, rowData) {

        	var url = Onluy.basePath()+AuthUserRigthModel.url+'/del'; 
          
        		Onluy.ajax.getData(url,rowData,Onluy.secretkey, function(result){
        			 var success = result.success;
        			 //Onluy.easyui.ShowMsg(success ? "提示" : "错误",result.msg);
        	         if (success) { 
        	        	 
        	         }
        		},function(error){
        			//AuthUserRigthModel.ShowException(error);
        		} ); 
        },
       
        onBeforeLoad: function (param) { 
        	
        	$('#AuthUserRigth_Grid').datagrid('clearSelections');
        	
            param['catchKey'] = Math.random();
        	
        	var datatype=$('#datatype_sel').combobox('getValue');
        	param['datatype'] = datatype;
        	
        	var userrow=$('#App_USER_Grid').datagrid('getSelected');
        	if(userrow){
        		param['userid']=userrow['userId'];
        	} 
        	  
        	
            param['name'] = $('#AuthUserRigth_ss').searchbox('getName');
            param['value'] = $('#AuthUserRigth_ss').searchbox('getValue');
        }
    });
    //设置分页控件  
    var p = $('#AuthUserRigth_Grid').datagrid('getPager');
    $(p).pagination({
        pageSize: 20, //每页显示的记录条数，默认为10  
        pageList: [20, 30, 50, 100], //可以设置每页记录条数的列表  
        beforePageText: '第', //页数文本框前显示的汉字  
        afterPageText: '页    共 {pages} 页',
        displayMsg: '当前显示 {from} - {to} 条记录   共 {total} 条记录',
        onBeforeRefresh: function () {
            $(this).pagination('loading');
            $(this).pagination('loaded');
        }
    });

});



